package org.example.springbootdemo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Themberfue
 * @date: 2025/1/21 11:36
 * @description:
 */
@RequestMapping("/calc")
@RestController
public class CalcController {
    @RequestMapping("/sum")
    public String sum(Integer num1, Integer num2) {
        if (num1 == null || num2 == null) {
            return "传递的数字不合法";
        }
        return "<h1>相加的结果为：" + (num1 + num2) + "</h1>";
    }

    @RequestMapping("/sub")
    public String sub(Integer num1, Integer num2) {
        if (num1 == null || num2 == null) {
            return "传递的数字不合法";
        }
        return "<h1>相减的结果为：" + (num1 - num2) + "</h1>";
    }

    @RequestMapping("/mul")
    public String mul(Integer num1, Integer num2) {
        if (num1 == null || num2 == null) {
            return "传递的数字不合法";
        }
        return "<h1>相乘的结果为：" + (num1 * num2) + "</h1>";
    }

    @RequestMapping("/div")
    public String div(Integer num1, Integer num2) {
        if (num1 == null || num2 == null || num2 == 0) {
            return "传递的数字不合法";
        }
        return "<h1>相除的结果为：" + (num1 / num2) + "</h1>";
    }
}
